package org.opensourcedea.gui.menu;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;

public class HelpAboutDialog extends Dialog {
	Object result;
	 
	public HelpAboutDialog (Shell parent, int style) {
		super (parent, style);
	}
	
	public HelpAboutDialog (Shell parent) {
		this (parent, 0);
	}
	
	public Object open () {
		Shell parent = getParent();
		final Shell shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
		shell.setText("About OSDEA");
		Image potIcon = new Image(shell.getDisplay(), this.getClass().getResourceAsStream("pot2422-48x48x32.png"));
		shell.setImage(potIcon);
		
		shell.setSize(500, 210);

		
		Label label = new Label(shell,SWT.CENTER | SWT.BORDER);
		label.setImage(potIcon);
		Device device = Display.getCurrent ();
		Color black = new Color (device, 63, 76, 107);
		label.setBackground(black);
		label.setBounds(0, 0, 68, 130);
		//label.pack();
		
		
		Text textbox = new Text(shell, SWT.MULTI | SWT.BORDER);
		textbox.setText("OSDEA is a free open source software\n\n" + 
		"Version 0.50\n\n" +
		"This software is distributed under GPL3 (http://gplv3.fsf.org/)\n\n" +
		"More information on OSDEA can be found at http://www.opensourcedea.org.");
		textbox.setBounds(68, 0, 426, 130);
		
		Button okButton = new Button(shell, SWT.PUSH);
		okButton.setText("OK");
		okButton.setBounds(215, 145, 80, 20);
		okButton.addMouseListener(new MouseListener()  {
		      public void mouseDown(MouseEvent e) {
		    	  shell.close();
		        }

		        public void mouseUp(MouseEvent e) {
		        	shell.close();
		        }

		        public void mouseDoubleClick(MouseEvent e) {

		        }
		      });
		

		
		shell.open();
		Display display = parent.getDisplay();
		
		while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) display.sleep();
		}
		
		return result;
	}
}
